From a815f102993a6a6f12179f9a5bd666980855e8be Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 11 Jan 2012 05:17:35 +0100 Subject: [PATCH] API: Add gtk_style_context_get_section() This API allows querying the location where style properties were defined. An example implementation will be committed soon. --- docs/reference/gtk/gtk3-sections.txt | 1 + gtk/gtk.symbols | 1 + gtk/gtkstylecontext.c | 42 ++++++++++++++++++++++++++++ gtk/gtkstylecontext.h | 3 ++ 4 files changed, 47 insertions(+) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 6f0402506f..f614e684e4 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5689,6 +5689,7 @@ gtk_style_context_get_style gtk_style_context_get_style_property gtk_style_context_get_style_valist gtk_style_context_get_valist +gtk_style_context_get_section gtk_style_context_get_color gtk_style_context_get_background_color gtk_style_context_get_border_color diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 8a83719e85..59df40ce7a 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2551,6 +2551,7 @@ gtk_style_context_get_parent gtk_style_context_get_path gtk_style_context_get_property gtk_style_context_get_screen +gtk_style_context_get_section gtk_style_context_get_state gtk_style_context_get_style gtk_style_context_get_style_property diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 2c1d8eb383..a39cf5abfd 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -1399,6 +1399,48 @@ gtk_style_context_remove_provider_for_screen (GdkScreen *screen, } } +/** + * gtk_style_context_get_section: + * @context: a #GtkStyleContext + * @property: style property name + * + * Queries the location in the CSS where @property was defined for the + * current @context. Note that the state to be queried is taken from + * gtk_style_context_get_state(). + * + * If the location is not available, %NULL will be returned. The + * location might not be available for various reasons, such as the + * property being overridden, @property not naming a supported CSS + * property or tracking of definitions being disabled for performance + * reasons. + * + * Shorthand CSS properties cannot be queried for a location and will + * always return %NULL. + * + * Returns: %NULL or the section where value was defined + **/ +GtkCssSection * +gtk_style_context_get_section (GtkStyleContext *context, + const gchar *property) +{ + GtkStyleContextPrivate *priv; + GtkStyleProperty *prop; + StyleData *data; + + g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL); + g_return_val_if_fail (property != NULL, NULL); + + priv = context->priv; + g_return_val_if_fail (priv->widget_path != NULL, NULL); + + prop = _gtk_style_property_lookup (property); + if (!GTK_IS_CSS_STYLE_PROPERTY (prop)) + return NULL; + + data = style_data_lookup (context, gtk_style_context_get_state (context)); + return _gtk_css_computed_values_get_section (data->store, _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop))); +} + static const GValue * gtk_style_context_query_func (guint id, gpointer values) diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h index afdeb7b686..9a76c54468 100644 --- a/gtk/gtkstylecontext.h +++ b/gtk/gtkstylecontext.h @@ -25,6 +25,7 @@ #define __GTK_STYLE_CONTEXT_H__ #include +#include #include #include #include @@ -717,6 +718,8 @@ void gtk_style_context_remove_provider (GtkStyleContext *context, void gtk_style_context_save (GtkStyleContext *context); void gtk_style_context_restore (GtkStyleContext *context); +GtkCssSection * gtk_style_context_get_section (GtkStyleContext *context, + const gchar *property); void gtk_style_context_get_property (GtkStyleContext *context, const gchar *property, GtkStateFlags state, -- 2.30.2